const { NODE_ENV, VUE_APP_PORT, VUE_APP_MOCK } = process.env

const path = require('path')

const pkg = require(path.resolve(__dirname, './package.json'))
process.env.VUE_APP_NAME = pkg.name

module.exports = {
  // publicPath: '/',
  // outputDir: 'dist',
  // productionSourceMap: false,
  lintOnSave: true,
  devServer: {
    proxy: {
      '/UMC': {
        target: 'http://sso.kukahome-internal.com',
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/UMC': '',
        },
      },
      '/oauth': {
        target: 'http://fat-tplatform.k8s.kukasofa.com:8080/api/authentication',
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/oauth': '',
        },
      },
      '/management-portal': {
        target: 'http://fat-tplatform.k8s.kukasofa.com:8080/api/portal',
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/management-portal': '',
        },
      },
      '/management-function-menu': {
        target: 'http://fat-tplatform.k8s.kukasofa.com:8080/api/functionmenu/',
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/management-function-menu': '',
        },
      },
      '/management-general': {
        target: 'http://fat-tplatform.k8s.kukasofa.com:8080/api/message',
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/management-general': '',
        },
      },
      '/management-application': {
        target: 'http://fat-tplatform.k8s.kukasofa.com:8080/api/application',
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/management-application': '',
        },
      },
      '/management-log': {
        target: 'http://fat-tplatform.k8s.kukasofa.com:8080/api/log',
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/management-log': '',
        },
      },
      '/management-authority': {
        target: 'http://fat-tplatform.k8s.kukasofa.com:8080/api/authority',
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/management-authority': '',
        },
      },
    },
    port: VUE_APP_PORT || 4000,
    headers: { 'Access-Control-Allow-Origin': '*' },
  },

  css: {
    loaderOptions: {
      less: {
        lessOptions: {
          javascriptEnabled: true,
        },
        // 添加一些全局变量
        additionalData: `@import "${path.resolve(__dirname, './src/assets/css/variables.less')}";`,
      },
    },
  },
  runtimeCompiler: true, //开发环境编译时组件报错
  // 修改webpack的配置
  configureWebpack: {
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
        assets: path.resolve(__dirname, 'src/assets'),
      },
    },
    // 不需要打包的插件
    externals: {
      // 'vue': 'Vue',
      // 'vue-router': 'VueRouter',
    },
  },
  chainWebpack(config) {
    // 内置的 svg Rule 添加 exclude
    config.module
      .rule('svg')
      .exclude.add(/iconsvg/)
      .end()

    // 添加 svg-sprite-loader Rule
    config.module
      .rule('svg-sprite-loader')
      .test(/.svg$/)
      .include.add(/iconsvg/)
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')

    // 添加 svgo Rule
    config.module
      .rule('svgo')
      .test(/.svg$/)
      .include.add(/iconsvg/)
      .end()
      .use('svgo-loader')
      .loader('svgo-loader')
      .options({
        // externalConfig 配置特殊不是相对路径，起始路径是根目录
        externalConfig: './src/assets/iconsvg/svgo.yml',
      })
  },
}
